<html>
<?php
    require_once("menu.php");
	require_once('controllers/tabella_classifica.php');
	require_once('controllers/calendari.php');
	require_once('controllers/lega.php');
	global $TC_CAMPIONATO, $TC_COPPA_A, $TC_COPPA_B, $TC_SEMIFINALE, $TC_FINALE_3_4, $TC_FINALE;
	$lega_id = -1;
	$cur_lega=null;
	if(isset($_GET['l'])){
		$lega_id = $_GET['l'];
	}else{
		$lega_id = Lega::getIdPrimaLega();
	}
	
	function printClassifica($tipo, $lega_id){
		echo "<table class='classifica' cellspacing='1' >
			<tr>
				<td class='classificaHeader'>&nbsp;</td>
				<td class='classificaHeader'>ALLENATORE</td>
				<td class='classificaHeader'>SQUADRA</td>
				<td class='classificaHeader'>PUNTI</td>
				<td class='classificaHeader'>G.</td>
				<td class='classificaHeader'>V.</td>
				<td class='classificaHeader'>S.</td>
				<td class='classificaHeader'>N.</td>
				<td class='classificaHeader'>G.F.</td>
				<td class='classificaHeader'>G.S.</td>
				<td class='classificaHeader'>D.R.</td>
				<td class='classificaHeader'>MEDIA</td>
				<td class='classificaHeader'>TOT</td>
			</tr>";
		
			
			$campionato = new TabellaClassifica($tipo, $lega_id);
			//gli elementi della classifica arrivano già ordinati
			//in base all'ordine in classifica
			for($i=0; $i < $campionato->getItemsCount(); $i++){
				$p = $campionato->getItem($i);
				$alt = $i%2;
				echo '<tr>';
				echo "<td class='classifica rowClassifica_$alt'>" . ($i+1) . "</td>"; //posizione in classifica
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getAllenatore() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getSquadra() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getPunti() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getGareggiate() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getVinte() . " </td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getSconfitte() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getNulle() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getGolFatti() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getGolSubiti() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getDiffReti() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getMediaPunti() . "</td>";
				echo "<td class='classifica rowClassifica_$alt'> " . $p->getTotPunti() . "</td>";
				echo '</tr>';
			} 
		echo "</table>";
	}
	
	
	$htmlLeghe = getMenuLeghe("?", $lega_id, $cur_lega);
?>
	<head>
		<title>Fantacalcio - Classifica</title>
		<link rel="stylesheet" href="fantacalcio.css" type="text/css"/>
		<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	</head>
	<body>
		<table class="pageTable" cellpadding='0' cellspacing='0'>
			<tr>
				<td>
					<?php echo printMasterMenu('Classifiche'); ?>
					
				</td>
				
			</tr>
			<tr>
				<td class='contentPage'>
					<table style="width:100%">
						<tr>
							<td colspan="2" class="pageTitle">Classifica lega <?php echo  $cur_lega->getNome();?></td>
						</tr>
						<tr>
							<td style='vertical-align:top;width:200px;vertical-align:top;'><?php echo $htmlLeghe; ?></td>
							<td style='vertical-align:top;'>
								<table style='width:100%'>
									<?php if($cur_lega->getCompetizione()==$CALENDARIO_CAMPIONATO){ ?>
									<tr>
										<td colspan="2" class="pageTitle">Classifica campionato</td>
										
									</tr>
									<tr>
										<td>
											<?php printClassifica($TC_CAMPIONATO, $lega_id); ?>
											
										</td>
									</tr>
									<?php } else { ?>
									<tr>
										<td colspan="2" class="pageTitle">Classifica coppa - Girone A</td>
										
									</tr>
									<tr>
										<td>
											<?php printClassifica($TC_COPPA_A, $lega_id); ?>
											
										</td>
									</tr>
									
									<tr>
										<td colspan="2" class="pageTitle">Classifica coppa - Girone B</td>
										
									</tr>
									<tr>
										<td>
											<?php printClassifica($TC_COPPA_B, $lega_id); ?>
										</td>
									</tr>
									<?php }?>
								</table>
							</td>
						</tr>

					</table>
				</td>
			</tr>
			<tr>
				<td>
					<?php printFooter() ?>
				</td>
			</tr>
		</table>
	</body>
</html>